package top.wardyan.wmes.rfid.vo;


import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;

import top.wardyan.wmes.constant.LangType;
import top.wardyan.wmes.constant.ModelType;
import top.wardyan.wmes.constant.Status;
import top.wardyan.wmes.constant.UseType;
import top.wardyan.wmes.util.BillNoUtil;

public class Device {
	
	//Integer MAXPARAM = ConfigProp.load().getInt("rfid.maxparamrecord", 100);

	/** 设备ID **/
	Integer deviceID = 0;
	
	/** 组号 **/
	Integer gid = 0;
	
	/** 编号 **/
	Integer did = 0;
	
	/** 工位机状态 **/
	Status status = Status.OFF;
	
	/** 工位机型号 **/
	ModelType model = ModelType.MT600;
	
	/** 用途/功能 **/
	UseType usetype = UseType.PROD_RECEIVE_PERSONAL;
	
	/** 工位机的语言 **/
	LangType lang = LangType.CHINESE;
	
	/** 工位机上的步骤 **/
	Integer step = 0;
	
	/** 不需要名字。看组号和编号就够了 **/
	// String name;

	/** 所在部门 **/
	Dept dept;
	
	/** 在线员工 **/
	Empl empl;
	
	/** 在线的小组 **/
	Team team;
	
	/** 小组成员 **/
	List<Empl> teamempls;
	
	/** 设备选项 **/
	Map<Integer, Object> options;
	
	/** 当前在做的批号 **/
	Prod po;
	
	/** 当前在做的工序列表 **/
	List<BillNo> billNos;
	
	/** 上次上报指令时间。用于阻止短时间内重复上报数据 **/
	Long lastTime = 0L;
	
	/** 下次上报指令时间，至少要过了这个时间才允许再上报，用于保护需要时间的保存数据任务 **/
	Long nextTime = 0L;
	
	/** 最近的指令。根据设定来保留数量 不，不需要这样缓存， 直接记录到数据库里去，需要的时候再去查出来 **/
	Queue<Param> params = new LinkedList<>();
	/** 上一次刷的扎卡 **/
	// Long bc;
	Card card;
	
	/** 上一次刷的RFID卡 如果不是刷卡则不会记录到这里来，但会清空这里。也就是说，上一次是刷卡则记录到这里，上一次不是刷卡则重置这里 **/
	// String card;
	String rfidNo;
	
	/** 上一次生成的指令 **/
	Command cmd;
	
	Integer pageNo;
	// Integer pageSize;
	
	
	/** 缓存的数据 **/
	Map<String, Object> datas = new HashMap<>();
	
	/** 生成的工序号用于显示，类似：2;3;4:裁剪;剪线;包装 **/
	String billNameList;
	
	public Integer getDeviceID() {
		return deviceID;
	}

	public Integer getGid() {
		return gid;
	}

	public Integer getDid() {
		return did;
	}

	public Device setDeviceID(Integer deviceID) {
		this.deviceID = deviceID;
		return this;
	}

	public Device setGid(Integer gid) {
		this.gid = gid;
		return this;
	}

	public Device setDid(Integer did) {
		this.did = did;
		return this;
	}

	public Status getStatus() {
		return status;
	}

	public ModelType getModel() {
		return model;
	}

	public UseType getUsetype() {
		return usetype;
	}

	public LangType getLang() {
		return lang;
	}

	public Dept getDept() {
		return dept;
	}

	public Empl getEmpl() {
		return empl;
	}

	public Team getTeam() {
		return team;
	}

	public List<Empl> getTeamempls() {
		return teamempls;
	}

	public Map<Integer, Object> getOptions() {
		return options;
	}

	public Prod getPo() {
		return po;
	}

	public List<BillNo> getBillNos() {
		return billNos;
	}

	public Long getLastTime() {
		return lastTime;
	}

	public Long getNextTime() {
		return nextTime;
	}


	public Device setStatus(Status status) {
		this.status = status;
		return this;
	}

	public Device setModel(ModelType model) {
		this.model = model;
		return this;
	}

	public Device setUsetype(UseType usetype) {
		this.usetype = usetype;
		return this;
	}

	public Device setLang(LangType lang) {
		this.lang = lang;
		return this;
	}

	public Device setDept(Dept dept) {
		this.dept = dept;
		return this;
	}

	public Device setEmpl(Empl empl) {
		this.empl = empl;
		return this;
	}

	public Device setTeam(Team team) {
		this.team = team;
		return this;
	}

	public Device setTeamempls(List<Empl> teamempls) {
		this.teamempls = teamempls;
		return this;
	}

	public Device setOptions(Map<Integer, Object> options) {
		this.options = options;
		return this;
	}
//
	public Device setPo(Prod po) {
		this.po = po;
		return this;
	}

	public Device setBillNos(List<BillNo> billNos) {
		this.billNos = billNos;
		this.billNameList = BillNoUtil.mapToStr(billNos, ";");
		return this;
	}

	public Device setLastTime(Long lastTime) {
		this.lastTime = lastTime;
		return this;
	}

	public Device setNextTime(Long nextTime) {
		this.nextTime = nextTime;
		return this;
	}

	public Integer getStep() {
		return step;
	}

	public Device setStep(Integer step) {
		this.step = step;
		return this;
	}
	
	/** 2;3;4:裁剪;剪线;包装 **/
	public String getBillNaneList() {
		if(this.billNameList == null) {
			billNameList = "";
		}
		return this.billNameList;
	}

//	public Long getBc() {
//		return bc;
//	}
//
//	public String getCard() {
//		return card;
//	}
//
//	public Device setBc(Long bc) {
//		this.bc = bc;
//		return this;
//	}
//
//	public Device setCard(String card) {
//		this.card = card;
//		return this;
//	}

	public Command getCmd() {
		return cmd;
	}

	public Device setCmd(Command cmd) {
		this.cmd = cmd;
		return this;
	}

	public Card getCard() {
		return card;
	}

	public String getRfidNo() {
		return rfidNo;
	}

	public Device setCard(Card card) {
		this.card = card;
		return this;
	}

	public Device setRfidNo(String rfidNo) {
		this.rfidNo = rfidNo;
		return this;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public Device setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
		return this;
	}

	public Map<String, Object> getDatas() {
		return datas;
	}

	public Device setDatas(Map<String, Object> datas) {
		this.datas = datas;
		return this;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getData(String key) {
		return (T)datas.get(key);
	}
	public Device setData(String key, Object data) {
		datas.put(key, data);
		return this;
	}

//	public Device setParams(Queue<Param> params) {
//		this.params = params;
//		return this;
//	}
//	
//	public Device addParam(Param param) {
//		params.offer(param);
//		return this;
//	}
//	public Device removeParam() {
//		params.poll();	// 移除最后一个
//		return this;
//	}
	
	
}
